﻿using Castle.DynamicProxy;
using StackExchange.Profiling;
using System;
using System.Collections.Generic;
using System.Text;

namespace Core.Infrastructures.Cores.Injections.Interceptors
{
    public partial class ProfilerInterceptor : IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            var method = invocation.MethodInvocationTarget ?? invocation.Method;    // 获取当前执行的方法对象
            var reflectedType = method.ReflectedType;   // 获取当前方法所在的类类型

            MiniProfiler.Current.Step($"{reflectedType.FullName}.{method.Name}");

            try
            {
                invocation.Proceed();
            }
            catch (Exception ex)
            {
                MiniProfiler.Current.CustomTiming("Errors：", ex.Message);
                throw;
            }
        }
    }
}
